
/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

/**
 * 
 * @param {*} value 
 * @returns 
 */
export function required(value) {  
  if (!value) {  
    return 'This field is required.';  
  }  
  return null;  
}  

/**
 * 
 * @param {*} value 
 * @returns 
 */
export function email(value) {  
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;  
  if (!emailRegex.test(value)) {  
    return 'Please enter a valid email address.';  
  }  
  return null;  
}

